package com.woniuxy.educationplatform.controller;

import com.woniuxy.educationplatform.bean.ProjectBean;
import com.woniuxy.educationplatform.bean.ResultMsg;
import com.woniuxy.educationplatform.bean.SubjectBean;
import com.woniuxy.educationplatform.service.IProjectService;
import com.woniuxy.educationplatform.service.ISubjectService;
import com.woniuxy.educationplatform.service.ITeacherService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Resource
    private IProjectService projectServiceImpl;
    @Resource
    private ISubjectService subjectServiceImpl;
    @Resource
    private ITeacherService teacherServiceImpl;

    /**
     * 新增项目
     * @param
     * @return
     */
    @RequestMapping(value ="/more",produces = {"application/json;charset=utf-8"})
    public List<SubjectBean> saveProject(String projName, String subjectName){
        System.out.println("来到控制器了");
        ProjectBean projectBean=new ProjectBean();
        SubjectBean subjectBean=new SubjectBean();
        //将前端传过来的值，封装到projectBean中,并将id返回回来

        projectBean.setProjName(projName);

        System.out.println(projName);
        System.out.println(subjectName);
        projectServiceImpl.saveProjectBean(projectBean);
        Long id = projectServiceImpl.findMaxId();
        System.out.println(projectBean);

        projectBean.setId(id);
        System.out.println(id);
        subjectBean.setProjectBean(projectBean);
        subjectBean.setSubjectName(subjectName);
        System.out.println(subjectBean);
        subjectServiceImpl.saveSubjectBean(subjectBean,id);

        List<SubjectBean> list=subjectServiceImpl.findAll();
        return list;

    }

    @RequestMapping("/getProject")
    String[] getProject(){
        return teacherServiceImpl.getProject();
    }

    @RequestMapping("del")
    public void delete(Long id){
        System.out.println("开始删除程序");
        System.out.println(id);
        subjectServiceImpl.deletdSubjectBean(id);
        System.out.println("删除完成");
    }
}
